from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models


# 文章标签
class Tag(models.Model):
    name = models.CharField('标签名称', max_length=20, unique=True)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    update_time = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        db_table = 'tag'
        verbose_name = '标签'
        verbose_name_plural = '标签'

    def __str__(self):
        return self.name


# 文章
class Article(models.Model):
    title = models.CharField('标题', max_length=30, unique=True)
    image = models.ImageField('封面', blank=True)
    author = models.CharField('作者', max_length=20, default='admin')
    content = RichTextUploadingField('内容', default='')
    tag = models.ManyToManyField(Tag, verbose_name='标签')
    create_time = models.DateTimeField('创建时间', auto_now_add=True)
    update_time = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        db_table = 'article'
        verbose_name = '文章'
        verbose_name_plural = '文章'

    def __str__(self):
        return self.title
